﻿using System;

namespace Geometry
{
    public class Line : LineString
    {
        #region 构造器
        public Line(string id, Point pointFrom, Point pointTo)
        {
            this.id = id;
            PointFrom = pointFrom;
            PointTo = pointTo;
            PointList.Add(pointFrom);
            PointList.Add(pointTo);
            SetLength();
            SetEnvelope();
        }
        public Line(Point pointFrom, Point pointTo)
        {
            PointFrom = pointFrom;
            PointTo = pointTo;
            PointList.Add(pointFrom);
            PointList.Add(pointTo);
            SetLength();
            SetEnvelope();
        }
        public Line() { }
        #endregion

        #region 方法
        //public PolyineWithPolylineRelEnum GetLineWithLineRel(Line lineOther)
        //{
        //    try
        //    {
        //        PointWtihPolylineRelEnum pointFromRel = PointFrom.GetPointWithLineRel(lineOther);
        //        PointWtihPolylineRelEnum pointToRel = PointTo.GetPointWithLineRel(lineOther);
        //        Vector v1 = new Vector("v1", this);
        //        Vector v2 = new Vector("v2", lineOther);
        //        double forkMultiply = v1.GetCrossProduct(v2);
        //        if (pointFromRel == 0)
        //        {
        //            switch (pointToRel)
        //            {
        //                case PointWtihPolylineRelEnum.On_Line:
        //                    return PolyineWithPolylineRelEnum.Within;
        //                case PointWtihPolylineRelEnum.Out_LineExtend:
        //                    return PolyineWithPolylineRelEnum.Overlap;
        //                case PointWtihPolylineRelEnum.Out_Left:
        //                    return PolyineWithPolylineRelEnum.Touch_Left;
        //                case PointWtihPolylineRelEnum.Out_Right:
        //                    return PolyineWithPolylineRelEnum.Touch_Right;
        //            }
        //            return PolyineWithPolylineRelEnum.NULL;
        //        }
        //        else if (pointFromRel == PointWtihPolylineRelEnum.Out_LineExtend)
        //        {
        //            switch (pointToRel)
        //            {
        //                case PointWtihPolylineRelEnum.On_Line:
        //                    return PolyineWithPolylineRelEnum.Overlap;
        //                case PointWtihPolylineRelEnum.Out_LineExtend:
        //                    return PolyineWithPolylineRelEnum.Contain;
        //                case PointWtihPolylineRelEnum.Out_Left:
        //                    return PolyineWithPolylineRelEnum.Disjoint_Cross;
        //                case PointWtihPolylineRelEnum.Out_Right:
        //                    return PolyineWithPolylineRelEnum.Disjoint_Cross;
        //            }
        //            return PolyineWithPolylineRelEnum.NULL;
        //        }
        //        else if (pointFromRel == PointWtihPolylineRelEnum.Out_Left)
        //        {
        //            switch (pointToRel)
        //            {
        //                case PointWtihPolylineRelEnum.On_Line:
        //                    return PolyineWithPolylineRelEnum.Touch_Left;
        //                case PointWtihPolylineRelEnum.Out_LineExtend:
        //                    return PolyineWithPolylineRelEnum.Disjoint_Cross;
        //                case PointWtihPolylineRelEnum.Out_Left:
        //                    {
        //                        if (forkMultiply == 0)
        //                            return PolyineWithPolylineRelEnum.Disjoint_Parallel;
        //                        else
        //                            return PolyineWithPolylineRelEnum.Disjoint_Cross;
        //                    }
        //                case PointWtihPolylineRelEnum.Out_Right:
        //                    return PolyineWithPolylineRelEnum.Cross;
        //            }
        //            return PolyineWithPolylineRelEnum.NULL;
        //        }
        //        else
        //        {
        //            switch (pointToRel)
        //            {
        //                case PointWtihPolylineRelEnum.On_Line:
        //                    return PolyineWithPolylineRelEnum.Touch_Right;
        //                case PointWtihPolylineRelEnum.Out_LineExtend:
        //                    return PolyineWithPolylineRelEnum.Disjoint_Cross;
        //                case PointWtihPolylineRelEnum.Out_Left:
        //                    return PolyineWithPolylineRelEnum.Cross;
        //                case PointWtihPolylineRelEnum.Out_Right:
        //                    {
        //                        if (forkMultiply == 0)
        //                            return PolyineWithPolylineRelEnum.Disjoint_Parallel;
        //                        else
        //                            return PolyineWithPolylineRelEnum.Disjoint_Cross;
        //                    }
        //            }
        //            return PolyineWithPolylineRelEnum.NULL;
        //        }
        //    }
        //    catch (Exception ex)
        //    {
        //        Console.WriteLine(ex);
        //        return PolyineWithPolylineRelEnum.NULL;
        //    }
        //}

        /// <summary>
        /// 快速排斥试验
        /// </summary>
        /// <param name="line1">线段1</param>
        /// <param name="line2">线段2</param>
        /// <returns>是否通过试验</returns>
        //public bool LineInstect_RapidTest(Line line1, Line line2)
        //{
        //    double X1start = line1.PointFrom.X;
        //    double X1end = line1.PointTo.X;
        //    double X2begin = line2.PointFrom.X;
        //    double X2end = line2.PointTo.X;
        //    double Y1begin = line1.PointFrom.Y;
        //    double Y1end = line1.PointTo.Y;
        //    double Y2begin = line2.PointFrom.Y;
        //    double Y2end = line2.PointTo.Y;
        //    if (Compare.minTwoNum(X1start, X1end) <= Compare.maxTwoNum(X2begin, X2end) &&
        //        Compare.minTwoNum(X2begin, X2end) <= Compare.maxTwoNum(X1start, X1end) &&
        //        Compare.minTwoNum(Y1begin, Y1end) <= Compare.maxTwoNum(Y2begin, Y2end) &&
        //        Compare.minTwoNum(Y2begin, Y2end) <= Compare.maxTwoNum(Y1begin, Y1end))
        //    {
        //        return true;
        //    }
        //    else
        //        return false;
        //}
        #endregion
    }
}
